/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * CollectModePanel.java
 *
 * Created on 2011-4-28, 16:59:09
 */

package com.iduxs.collect.frame.collect;

import java.util.Enumeration;
import javax.swing.AbstractButton;

/**
 *
 * @author Administrator
 */
public class CollectModePanel extends javax.swing.JPanel {

    public final static String REMOTE_LAST_LIST_TYPE = "按目标站页面获得编号，一般监控最新列表，一行一个地址";
    public final static String REMOTE_NO_SEQUENCE_TYPE = "按目标站编号顺序";
    public final static String REMOTE_NO_CUSTOMIZE_TYPE = "按目标站自定义编号";
    public final static String LOCAL_NO_SEQUENCE_TYPE = "按自己站编号顺序";
    public final static String LOCAL_NO_CUSTOMIZE_TYPE = "按自己站自定义编号";
    public final static String OTHER_LAST_LIST_TYPE = "按其它站列表搜索";

    /** Creates new form CollectModePanel */
    public CollectModePanel() {
        initComponents();
        init();
    }

    private void init() {
        jRadioButton1.setText(REMOTE_LAST_LIST_TYPE);
        jRadioButton2.setText(REMOTE_NO_SEQUENCE_TYPE);
        jRadioButton3.setText(REMOTE_NO_CUSTOMIZE_TYPE);
        jRadioButton4.setText(LOCAL_NO_SEQUENCE_TYPE);
        jRadioButton5.setText(LOCAL_NO_CUSTOMIZE_TYPE);
        jRadioButton6.setText(OTHER_LAST_LIST_TYPE);
    }

    public CollectMode getCollectMode() {
        CollectMode cm = new CollectMode();
        cm.setCollectSolutions(collectSolutionsItem.getSelectedItem().toString().trim());
        cm.setCollectRules(collectRulesItem.getSelectedItem().toString().trim());
        cm.setUrls(urlsText.getText().trim());
        cm.setRemoteNoStart(remoteNoStartText.getText().trim());
        cm.setRemoteNoEnd(remoteNoEndText.getText().trim());
        cm.setRemoteCustomizeNo(remoteCustomizeNoText.getText().trim());
        cm.setLocalNoStart(localNoStartText.getText().trim());
        cm.setLocalNoEnd(localNoEndText.getText().trim());
        cm.setLocalCustomizeNo(localCustomizeNoText.getText().trim());
        cm.setOtherUrl(otherUrlText.getText().trim());
        cm.setOtherFont(otherFontText.getText().trim());
        cm.setOtherRegular(otherRegularText.getText().trim());
        cm.setUseLog(useLogBox.isSelected());
        cm.setUseLoop(useLoopBox.isSelected());
        cm.setLoopInterval(Integer.valueOf(loopIntervalText.getValue().toString().trim()));
        Enumeration<AbstractButton> buttons =  buttonGroup.getElements();
        while (buttons.hasMoreElements()) {
            AbstractButton button = buttons.nextElement();
            if (button.isSelected()) {
                cm.setType(button.getText().trim());
                break;
            }
        }
        return cm;
    }

    public void setCollectMode(CollectMode cm) {
        collectSolutionsItem.setSelectedItem(cm.getCollectSolutions().trim());
        collectRulesItem.setSelectedItem(cm.getCollectRules().trim());
        urlsText.setText(cm.getUrls());
        remoteNoStartText.setText(cm.getRemoteNoStart());
        remoteNoEndText.setText(cm.getRemoteNoEnd());
        remoteCustomizeNoText.setText(cm.getRemoteCustomizeNo());
        localNoStartText.setText(cm.getLocalNoStart());
        localNoEndText.setText(cm.getLocalNoEnd());
        localCustomizeNoText.setText(cm.getLocalCustomizeNo());
        otherUrlText.setText(cm.getOtherUrl());
        otherFontText.setText(cm.getOtherFont());
        otherRegularText.setText(cm.getOtherRegular());
        useLogBox.setSelected(cm.getUseLog());
        useLoopBox.setSelected(cm.getUseLoop());
        loopIntervalText.setValue(cm.getLoopInterval());
        Enumeration<AbstractButton> buttons =  buttonGroup.getElements();
        while (buttons.hasMoreElements()) {
            AbstractButton button = buttons.nextElement();
            if (button.getText().trim().equals(cm.getType().trim())) {
                button.setSelected(true);
                break;
            }
        }
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        buttonGroup = new javax.swing.ButtonGroup();
        sdfs = new javax.swing.JLabel();
        collectSolutionsItem = new javax.swing.JComboBox();
        sdfs1 = new javax.swing.JLabel();
        collectRulesItem = new javax.swing.JComboBox();
        jRadioButton1 = new javax.swing.JRadioButton();
        jScrollPane1 = new javax.swing.JScrollPane();
        urlsText = new javax.swing.JTextArea();
        jRadioButton2 = new javax.swing.JRadioButton();
        jRadioButton3 = new javax.swing.JRadioButton();
        jRadioButton4 = new javax.swing.JRadioButton();
        jRadioButton5 = new javax.swing.JRadioButton();
        jRadioButton6 = new javax.swing.JRadioButton();
        loopIntervalText = new javax.swing.JSpinner();
        jLabel1 = new javax.swing.JLabel();
        useLoopBox = new javax.swing.JCheckBox();
        useLogBox = new javax.swing.JCheckBox();
        otherRegularText = new javax.swing.JTextField();
        otherFontText = new javax.swing.JTextField();
        otherUrlText = new javax.swing.JTextField();
        localCustomizeNoText = new javax.swing.JTextField();
        localNoStartText = new javax.swing.JTextField();
        localNoEndText = new javax.swing.JTextField();
        remoteCustomizeNoText = new javax.swing.JTextField();
        remoteNoStartText = new javax.swing.JTextField();
        remoteNoEndText = new javax.swing.JTextField();

        sdfs.setFont(new java.awt.Font("宋体", 0, 12)); // NOI18N
        sdfs.setText("采集方案");

        collectSolutionsItem.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));

        sdfs1.setFont(new java.awt.Font("宋体", 0, 12)); // NOI18N
        sdfs1.setText("采集规则");

        collectRulesItem.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));

        buttonGroup.add(jRadioButton1);
        jRadioButton1.setFont(new java.awt.Font("宋体", 0, 12)); // NOI18N
        jRadioButton1.setText("按目标站页面获得编号，一般监控最新列表，一行一个地址");

        urlsText.setColumns(20);
        urlsText.setRows(5);
        jScrollPane1.setViewportView(urlsText);

        buttonGroup.add(jRadioButton2);
        jRadioButton2.setFont(new java.awt.Font("宋体", 0, 12)); // NOI18N
        jRadioButton2.setText("按目标站编号顺序");

        buttonGroup.add(jRadioButton3);
        jRadioButton3.setFont(new java.awt.Font("宋体", 0, 12)); // NOI18N
        jRadioButton3.setText("按目标站自定义编号");

        buttonGroup.add(jRadioButton4);
        jRadioButton4.setFont(new java.awt.Font("宋体", 0, 12)); // NOI18N
        jRadioButton4.setText("按自己站编号顺序");

        buttonGroup.add(jRadioButton5);
        jRadioButton5.setFont(new java.awt.Font("宋体", 0, 12)); // NOI18N
        jRadioButton5.setText("按自己站自定义编号");

        buttonGroup.add(jRadioButton6);
        jRadioButton6.setFont(new java.awt.Font("宋体", 0, 12)); // NOI18N
        jRadioButton6.setText("按其它站列表搜索");

        jLabel1.setFont(new java.awt.Font("宋体", 0, 12)); // NOI18N
        jLabel1.setText("循环间隔时间(分钟)");

        useLoopBox.setFont(new java.awt.Font("宋体", 0, 12)); // NOI18N
        useLoopBox.setText("循环采集");

        useLogBox.setFont(new java.awt.Font("宋体", 0, 12)); // NOI18N
        useLogBox.setText("日志记录");

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jRadioButton1, javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
                        .addComponent(sdfs)
                        .addGap(18, 18, 18)
                        .addComponent(collectSolutionsItem, javax.swing.GroupLayout.PREFERRED_SIZE, 159, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(70, 70, 70)
                        .addComponent(sdfs1)
                        .addGap(18, 18, 18)
                        .addComponent(collectRulesItem, javax.swing.GroupLayout.PREFERRED_SIZE, 256, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(jScrollPane1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 622, Short.MAX_VALUE)
                            .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
                                .addComponent(jRadioButton4)
                                .addGap(18, 18, 18)
                                .addComponent(localNoStartText, javax.swing.GroupLayout.PREFERRED_SIZE, 115, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(localNoEndText, javax.swing.GroupLayout.DEFAULT_SIZE, 362, Short.MAX_VALUE))
                            .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
                                .addComponent(jRadioButton5)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(localCustomizeNoText, javax.swing.GroupLayout.DEFAULT_SIZE, 483, Short.MAX_VALUE))
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(useLogBox)
                                .addGap(18, 18, 18)
                                .addComponent(useLoopBox)
                                .addGap(18, 18, 18)
                                .addComponent(jLabel1)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(loopIntervalText, javax.swing.GroupLayout.PREFERRED_SIZE, 47, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(jRadioButton3)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(remoteCustomizeNoText, javax.swing.GroupLayout.DEFAULT_SIZE, 483, Short.MAX_VALUE))
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(jRadioButton2)
                                .addGap(18, 18, 18)
                                .addComponent(remoteNoStartText, javax.swing.GroupLayout.PREFERRED_SIZE, 115, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(remoteNoEndText, javax.swing.GroupLayout.DEFAULT_SIZE, 362, Short.MAX_VALUE))
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(jRadioButton6)
                                .addGap(18, 18, 18)
                                .addComponent(otherUrlText, javax.swing.GroupLayout.PREFERRED_SIZE, 115, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(otherFontText, javax.swing.GroupLayout.PREFERRED_SIZE, 74, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addComponent(otherRegularText, javax.swing.GroupLayout.PREFERRED_SIZE, 282, javax.swing.GroupLayout.PREFERRED_SIZE)))
                        .addGap(9, 9, 9)))
                .addGap(18, 18, 18))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(collectRulesItem, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(sdfs1))
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(sdfs)
                        .addComponent(collectSolutionsItem, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jRadioButton1)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 120, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jRadioButton2)
                    .addComponent(remoteNoStartText, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(remoteNoEndText, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jRadioButton3)
                    .addComponent(remoteCustomizeNoText, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jRadioButton4)
                    .addComponent(localNoStartText, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(localNoEndText, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jRadioButton5)
                    .addComponent(localCustomizeNoText, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(otherRegularText, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jRadioButton6)
                    .addComponent(otherFontText, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(otherUrlText, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(loopIntervalText, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel1)
                    .addComponent(useLoopBox)
                    .addComponent(useLogBox))
                .addContainerGap())
        );
    }// </editor-fold>//GEN-END:initComponents


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.ButtonGroup buttonGroup;
    private javax.swing.JComboBox collectRulesItem;
    private javax.swing.JComboBox collectSolutionsItem;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JRadioButton jRadioButton1;
    private javax.swing.JRadioButton jRadioButton2;
    private javax.swing.JRadioButton jRadioButton3;
    private javax.swing.JRadioButton jRadioButton4;
    private javax.swing.JRadioButton jRadioButton5;
    private javax.swing.JRadioButton jRadioButton6;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTextField localCustomizeNoText;
    private javax.swing.JTextField localNoEndText;
    private javax.swing.JTextField localNoStartText;
    private javax.swing.JSpinner loopIntervalText;
    private javax.swing.JTextField otherFontText;
    private javax.swing.JTextField otherRegularText;
    private javax.swing.JTextField otherUrlText;
    private javax.swing.JTextField remoteCustomizeNoText;
    private javax.swing.JTextField remoteNoEndText;
    private javax.swing.JTextField remoteNoStartText;
    private javax.swing.JLabel sdfs;
    private javax.swing.JLabel sdfs1;
    private javax.swing.JTextArea urlsText;
    private javax.swing.JCheckBox useLogBox;
    private javax.swing.JCheckBox useLoopBox;
    // End of variables declaration//GEN-END:variables

}
